package com.itheima.dao;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.jdbc.core.JdbcTemplate;

public class SingletonTemplate {
    private static JdbcTemplate jdbcTemplate = null;

    public static JdbcTemplate getJdbcTemplate() {
        if (jdbcTemplate == null) {
            jdbcTemplate = new JdbcTemplate();

            //初始化druid
            DruidDataSource druidDataSource = new DruidDataSource();
            druidDataSource.setDriverClassName("com.mysql.jdbc.driver");
            druidDataSource.setUrl("jdbc:mysql://127.0.0.1:3306/user_management");
            druidDataSource.setUsername("root");
            druidDataSource.setPassword("root"); //密码写入代码不是最佳实践

            jdbcTemplate.setDataSource(druidDataSource);
        }
        return jdbcTemplate;
    }
}
